package com.igeek.health.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.igeek.health.config.LoginUser;
import com.igeek.health.result.Result;
import com.igeek.health.service.IMenuService;
import com.igeek.health.vo.MenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author fengqq
 * @Description TODO
 * @Date 2024/9/10  15:03
 */
@RestController
@RequestMapping("/admin/menu")
@Api(tags = "菜单模块的控制层")
@Slf4j
public class MenuController {
    @Autowired
    private IMenuService menuService;

    @GetMapping("/findAll")
    @ApiOperation("查询动态菜单列表")
    public Result findAll(){
        //根据当前登录用户id查询动态菜单列表
        //获取security上下文中获取用户认证信息
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser principal = (LoginUser) authentication.getPrincipal();
        Integer id = principal.getUser().getId();
        List<MenuVO> result = menuService.findAll(id);
        log.info("result:{}",result);
        if(CollectionUtil.isNotEmpty(result)){
            return new Result(true,"菜单查询成功",result);
        }
        return new Result(false,"菜单查询失败");
    }
}
